package JFrame.Admin.UserManager;

import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.*;
import java.awt.event.ActionEvent;
import JFrame.*;
import serive.AdminService;
import serive.AdminServiceImpl;

public class DeleteUserJFrame extends JFrame {
    JFrame jFrame =this;
    AdminService adminService =new AdminServiceImpl();
    public DeleteUserJFrame() {
        initializing();
    }
    public void initializing(){
        JPanel panel=new JPanel();
        panel.setLayout(new GridLayout(2,2,10,10));
        panel.setBorder(new EmptyBorder(20, 20, 20, 20));
        add(panel);
        panel.setBackground(new Color(255, 255, 255));
        JLabel l_id =new JLabel("请输入要删除的用户ID:",SwingConstants.LEFT);
        JTextField t_id =new JTextField(SwingConstants.CENTER);
        JButton Yes =new JButton("确认");
        JButton Cancel =new JButton("取消");
        Yes.addActionListener(new AbstractAction() {
            @Override
            public void actionPerformed(ActionEvent e) {
                boolean delete = adminService.delete(t_id.getText());
                if (delete){
                    JOptionPane.showMessageDialog(null,
                            "删除成功", "！！！",JOptionPane.WARNING_MESSAGE);

                }else {
                    JOptionPane.showMessageDialog(null,
                            "删除失败，请输入正确的用户ID(如果用户的快件还存在，不能删除)", "！！！",JOptionPane.WARNING_MESSAGE);

                }
            }
        });
        Cancel.addActionListener(new AbstractAction() {
            @Override
            public void actionPerformed(ActionEvent e) {
                jFrame.dispose();
            }
        });
        Cancel.setBackground(new Color(102,204,255));
        Yes.setBackground(new Color(102,204,255));

        setSize(600,200);
        setTitle("删除用户——管理员");
        setResizable(false);

        setLocationRelativeTo(getOwner());
        Tools.setFonts(20,1,l_id,Yes,Cancel);
        Tools.setTextFieldCenter(t_id);
        Tools.addComponents(panel,l_id,t_id,Yes,Cancel);
        setVisible(true);
    }

}
